package servidor;

import java.rmi.*;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.net.*;
import java.io.*;
////////////////////////////////////////////////////////////////////////////////
public class Servidor {
////////////////////////////////////////////////////////////////////////////////
    public static void main(String args[]) {
        InputStreamReader is
                = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);
        String registryURL;
        try {
            startRegistry(1235);

            ServidorImpl exportedObj = new ServidorImpl();
            registryURL = "rmi://localhost:1235/alertasBursatiles";
            Naming.rebind(registryURL, exportedObj);
            System.out.println("Server ready.");

        } catch (RemoteException | MalformedURLException re) {
            System.out.println("Exception in HelloServer.main: " + re);
        }
    }
////////////////////////////////////////////////////////////////////////////////
    private static void startRegistry(int RMIPortNum)
            throws RemoteException {
        try {
            Registry registry = LocateRegistry.getRegistry(RMIPortNum);
            registry.list();  // This call will throw an exception if the registry does not already exist
        } catch (RemoteException e) {
            Registry registry = LocateRegistry.createRegistry(RMIPortNum);// No valid registry at that port.
        }
    }
////////////////////////////////////////////////////////////////////////////////
}
